<template>
  <el-form
    ref="validataForm"
    :model="formVal"
    label-width="160px"
    class="el-form pms-form"
    size="mini"
    disabled
    :inline="true"
    :rules="rules"
    style="line-height: 28px;"
  >
    <el-row :gutter="24" style="margin-right: 0px;" type="flex" justify="end" class="marginBottom14">
      <el-col :span="1.5" style="float: right;padding-right:0px;line-height: 0px;">
        <el-button v-if="AttachmentPassShow" class="pms-button-primary" :disabled="false" @click="AttachmentPass()">附件补传</el-button>
        <el-button v-if="AssetAssemblyShow" class="pms-button-primary" :disabled="false" @click="AssetAssembly()">财务系统资产装配</el-button>
        <el-button class="pms-button-primary" :disabled="false" @click="selectJGJSB()">查看竣工决算表</el-button>
        <el-button class="pms-button-primary" :disabled="false" @click="getFinancialTransferInfo()">获取财务转资信息</el-button>
      </el-col>
    </el-row>
    <el-row :gutter="24">
      <el-col :span="6">
        <el-form-item label="资产总金额" style="width:100%;" prop="zanguMoney">
          <el-input v-model.trim="formVal.zanguMoney" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="改造修理支出金额" style="width:100%;" prop="costAmount">
          <el-input v-model.trim="formVal.costAmount" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="正式竣工决算总金额" style="width:100%;" prop="forTotalMoney">
          <el-input v-model="formVal.forTotalMoney" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="正式竣工决算时间" style="width:100%;" prop="forMoneyTime">
          <el-input v-model="formVal.forMoneyTime" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="结算审定金额" style="width:100%;" prop="jisAppInvest">
          <el-input v-model.trim="formVal.jisAppInvest" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="结算送审时间" style="width:100%;" prop="jisSubTime">
          <el-input v-model="formVal.jisSubTime" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="结算审定时间" style="width:100%;" prop="jisAppTime">
          <el-input v-model="formVal.jisAppTime" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="暂估时间" style="width:100%;" prop="zanguTime">
          <el-input v-model="formVal.zanguTime" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="决算审定金额" style="width:100%;" prop="jusAppInvest">
          <el-input v-model.trim="formVal.jusAppInvest" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="决算送审时间" style="width:100%;" prop="jusSubTime">
          <el-input v-model="formVal.jusSubTime" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="决算审定时间" style="width:100%;" prop="jusAppTime">
          <el-input v-model="formVal.jusAppTime" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="项目关闭时间" style="width:100%;" prop="proCloseTime">
          <el-input v-model="formVal.proCloseTime" />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import {
  getSelectJGJSBConfigNew,
  getUserInfoNew,
  applyTokenByCodeNew,
  getIsPushNew,
  confirmationOfArrivalNew,
} from '@/api/actualBudget'
import { newOpenPostWindow } from '@/utils/newRequestCommonFormjs'
import { numberToQianFenWei } from '@/utils/numberToQianFenWei'
import {getTransferCapitalInfo} from "@/api/actualBudget/tFbusiness";
import {msgInfoEl} from "@/utils";

export default {
  // name: 'Prjbasedetail',
  name: 'BeCompletedDetail',
  props: ['formVal', 'urlList', 'lcList','prjId'],
  data() {
    return {
      rules: {
        zanguMoney: [
          { required: true, message: ' ', trigger: 'blur' }
        ],
        costAmount: [
          { required: true, message: ' ', trigger: 'blur' }
        ],
        forMoneyTime: [
          { required: true, message: ' ', trigger: 'blur' }
        ],
        forTotalMoney: [
        { required: true, message: ' ', trigger: 'blur' }
        ]
      },
      fileUrl: process.env.VUE_APP_ZHONGRUAN_URL,
      AssetAssemblyShow: false,
      AttachmentPassShow: false
    }
  },
  watch: {
    'formVal.zanguMoney': function(newVal, oldVal) {
        this.formVal.zanguMoney = numberToQianFenWei(newVal)
    },
    'formVal.costAmount': function(newVal, oldVal) {
        this.formVal.costAmount = numberToQianFenWei(newVal)
    },
    'formVal.forTotalMoney': function(newVal, oldVal) {
        this.formVal.forTotalMoney = numberToQianFenWei(newVal)
    },
    'formVal.jisAppInvest': function(newVal, oldVal) {
        this.formVal.jisAppInvest = numberToQianFenWei(newVal)
    },
    'formVal.jusAppInvest': function(newVal, oldVal) {
        this.formVal.jusAppInvest = numberToQianFenWei(newVal)
    }
  },
  methods: {
    // 查看 决算竣工表
    async selectJGJSB() {
      var getSelectJGJSBConfigList = {}
      var getUserInfoList = {}
      var applyTokenByCodeList = {}

      // 决算: 查询竣工决算表配置信息接口
      const getSelectJGJSBConfig = await getSelectJGJSBConfigNew({ itfCodeStatus: '0' })
      if (getSelectJGJSBConfig.code === '200') {
        getSelectJGJSBConfigList = getSelectJGJSBConfig.data
      }

      // 决算: 获取用户信息接口
      const getUserInfo = await getUserInfoNew({ })
      if (getUserInfo.code === '200') {
        getUserInfoList = getUserInfo.data
      }

      // 决算: 获取财务token(登录信息)接口
      const applyTokenByCode = await applyTokenByCodeNew({ serviceId: 'CHNTFMS', loginAcct: getUserInfoList.user.loginName })
      if (applyTokenByCode.code === '200') {
        applyTokenByCodeList = applyTokenByCode.data
          // 2022-04-28 跳转页面使用post方式
          var pwdaToken = applyTokenByCodeList.TOKEN
          var acctId = applyTokenByCodeList.ACCTID
          var toUrl = getSelectJGJSBConfigList.servUrl
          var params = {}
              params.pwdaToken = pwdaToken
              params.acctId = acctId
              params.Login = 'PMS_COST'
              params.AuthType = 'UserCode'
              params.AppCode = '0001'
              params.UserCode = getUserInfoList.user.loginName
              params.callType = '1'
              params.flag = '1'
              params.callPara = '/cwbase/web/session/gsprtf/adpdebug.aspx?ADPUrl=/cwbase/web/gspadp/debug/45b71827-ba5b-42db-9df2-b2acd53e620c/Index.html'
              console.log(toUrl, params, 'toUrlparams')
              newOpenPostWindow(toUrl, params)
      }
    },
    getFinancialTransferInfo(){
      getTransferCapitalInfo(this.prjId).then((res) => {
          if(+res.code === 200){
              this.formVal.zanguMoney = numberToQianFenWei(res.data.zanguMoney)
              this.formVal.zanguTime = res.data.zanguTime
              this.formVal.forTotalMoney = numberToQianFenWei(res.data.forTotalMoney)
              this.formVal.forMoneyTime = res.data.forMoneyTime
              if(res.message){
                  this.$message({
                      // 将html化
                      dangerouslyUseHTMLString: true,
                      message: res.message,
                      type: 'error'
                  })
              }else{
                  msgInfoEl({
                      type: 'success',
                      message: '获取成功'
                  })
              }
          }
      })
    },
    // 附件补传
    AttachmentPass() {
      const AttachmentPassUrl = this.fileUrl + 'attachmentPass'
      var params = {}
          params.prjId = this.lcList.bizObject.prjId
          params.token = this.urlList.token
      newOpenPostWindow(AttachmentPassUrl, params)
    },
    // 资产装配
    async AssetAssembly() {
      var arrivalState = false
      var prjId = this.lcList.bizObject.prjId
      var isPush = ''
      var getUserInfoList = {}
      var applyTokenByCodeList = {}
      var getSelectJGJSBConfigList = {}

      const getIsPush = await getIsPushNew({ prjId: prjId })
      if (getIsPush.code === '200') {
        isPush = getIsPush.data
      }
      if (isPush === '1') {
          const confirmationOfArrival = await confirmationOfArrivalNew({ prjId: prjId, queryType: '6' })
          if (confirmationOfArrival.code === '200') {
               arrivalState = true
          }
          if (confirmationOfArrival.code === '1019') {
            msgInfoEl({
            message: confirmationOfArrival.message || '操作异常',
            type: 'error'
          })
        }
      } else {
        this.$message({
            message: '物资未推送商合！',
            type: 'warning'
        })
      }

      if (arrivalState === false) {
        return
      }

      // 决算: 查询竣工决算表配置信息接口
      const getSelectJGJSBConfig = await getSelectJGJSBConfigNew({ itfCodeStatus: '1' })
      if (getSelectJGJSBConfig.code === '200') {
        getSelectJGJSBConfigList = getSelectJGJSBConfig.data
      }
      // 决算: 获取用户信息接口
      const getUserInfo = await getUserInfoNew({ })
      if (getUserInfo.code === '200') {
        getUserInfoList = getUserInfo.data
      }
     // 决算: 获取财务token(登录信息)接口
     const applyTokenByCode = await applyTokenByCodeNew({ serviceId: 'CHNTFMS', loginAcct: getUserInfoList.user.loginName })
      if (applyTokenByCode.code === '200') {
        applyTokenByCodeList = applyTokenByCode.data
          // 2022-04-28 跳转页面使用post方式
          var pwdaToken = applyTokenByCodeList.TOKEN
          var acctId = applyTokenByCodeList.ACCTID
          var toUrl = getSelectJGJSBConfigList.servUrl
          var params = {}
              params.pwdaToken = pwdaToken
              params.acctId = acctId
              params.Login = 'PMS_ZP'
              params.flag = '1'
              // params.STARTTIME = '2015-01-01'
              // params.ENDTIME = '2015-01-01'
              // params.DWBH = '100001'
              // params.XMBH = '23M12ZBZB011000037'
              console.log(toUrl, params, 'toUrlparams')
              newOpenPostWindow(toUrl, params)
      }
    },
    validataForm() {
      var flag = false
      this.$refs['validataForm'].validate((vide) => {
        flag = vide
      })
      return flag
    }
  }
}
</script>

